var express = require('express');
var app = express();
var ccap = require('ccap');
var bodyParser = require('body-parser');
var captcha = ccap({
    　　width:190,
    　　height:50,　
    　　offset:30,
    　　quality:100,
    　　fontsize:40,
    　　/*generate:function(){
    　　　　//自定义生成字符串
    　　　　//此方法可不要
               var str = "qQ";
               return str;
    　　}*/
    　　
    });
// 创建 application/x-www-form-urlencoded 编码解析
var urlencodedParser = bodyParser.urlencoded({ extended: false })
 
app.use(express.static('public'));
 
app.get('/index.htm', function (req, res) {
   res.sendFile( __dirname + "/" + "index.htm" );
})
 
app.get('/ccap', urlencodedParser, function (req, res) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    var ary = captcha.get();
    console.log(ary[0]);//字符串
    ary[1]=ary[1].toString('base64');
    res.end(JSON.stringify(ary));
})
 
var server = app.listen(8081, function () {
 
  var host = server.address().address
  var port = server.address().port
 
  console.log("应用实例，访问地址为 http://%s:%s", host, port)
 
})